import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Solution609 {
    public List<List<String>> findDuplicate(String[] paths) {
        Map<String,List<String>> map=new HashMap<>();
        for (String path : paths) {
            String[] target=path.split(" ");
            for (int i=1;i<target.length;i++){
                String t=target[i].substring(target[i].indexOf('(')+1,target[i].indexOf(')'));
                map.putIfAbsent(t,new ArrayList<>());
                map.get(t).add(target[0].concat("/").concat(target[i].substring(0,target[i].indexOf('('))));
            }
        }
        List<List<String>> lists=new ArrayList<>();
        for (Map.Entry<String, List<String>> stringListEntry : map.entrySet()) {
            if (stringListEntry.getValue().size()>1){
                lists.add(stringListEntry.getValue());
            }
        }
        return lists;
    }

    public static void main(String[] args) {
        System.out.println(new Solution609().findDuplicate(new String[]{"root/a 1.txt(abcd) 2.txt(efgh)","root/c 3.txt(abcd)","root/c/d 4.txt(efgh)","root 4.txt(efgh)"}));
    }
}
